package com.spn.blog.api.service.impl;

import com.spn.blog.common.vo.Result;
import com.spn.blog.api.component.KunlunSystemInfo;
import com.spn.blog.api.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;

@Service
public class SystemServiceImpl implements SystemService {

    @Autowired
    private KunlunSystemInfo kunlunSystemInfo;

    @Override
    public Result systeminfo() {
        Map<String, Map<String, Object>> res = new HashMap<>();
        Map jvm = kunlunSystemInfo.jvm();
        Map cpu = kunlunSystemInfo.cpu();
        Map disk = kunlunSystemInfo.disk();
        Map mem = kunlunSystemInfo.mem();
        try {
            Map env = kunlunSystemInfo.env();
            res.put("env", env);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
//        res.put("jvm", jvm);
        res.put("cpu", cpu);
        res.put("disk", disk);
        res.put("mem", mem);
        return Result.success(res);
    }
}
